function [tdata tlabels edata elabels] = getTrainingData(data, labels, split=0.5)

    tdata=tlabels=edata=elabels=[];
    
    positives = data(labels(:,1)==1,:);
    negatives = data(labels(:,1)==0,:);

    size(positives)
    size(negatives)

    total=min(size(positives,1),size(negatives,1));

    porder=randperm(size(positives,1));
    norder=randperm(size(negatives,1));
    
    split=floor(total*split);

    for(i=1:split)
        tdata=[tdata;negatives(norder(1,i),:);positives(porder(1,i),:)];
        tlabels=[tlabels;0;1];
    end;

    for(i=split+1:total)
        edata=[edata; negatives(norder(1,i),:); positives(porder(1,i),:)];
        elabels=[elabels;0;1];
    end;    
end;
